package day5;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {
	public static void main(String[] args) {
		
	}
	
//	1、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	求出上面数组中0-9分别出现的次数    
//	双重for循环
	@Test
	public void test1() {// Code review 代码审核
		int[] scores = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int[] counts = new int[10];// counts[0] 放0出现次数  counts[1] 放1出现次数
		for (int i = 0; i < scores.length; i++) {
			switch (scores[i]) {
			case 0:
				counts[0]++;
				// counts[scores[i]]++;
				break;
			case 1:
				counts[1]++;
				break;

			default:
				break;
			}
		}
		
		for (int i = 0; i < counts.length; i++) {
			System.out.println(i + "出现的" + counts[i] + "次数");
		}
	}
	
//	16、题目：一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。
//	char[] array = ['a' , 'b', 'c', 'b' , 'a'];
	@Test
	public void test3() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.nextLine(); // "dfhoid346#^& 6483^"
		char[] array = str.toCharArray();
		boolean isHuiWen = true;
		for (int i = 0; i < array.length / 2; i++) {
			if (array[i] != array[array.length-i-1]) {
				isHuiWen = false;
				break;
			}
		}
		
		if (isHuiWen) {
			System.out.println("是回文");
		} else {
			System.out.println("不是回文");
		}
	}
	
	
	// 17、输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
	@Test
	public void test55() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一个字符串：");
		String str = scanner.nextLine(); // "dfhoid346#^& 6483^"
		char[] array = str.toCharArray();
		int charCount = 0;
		int blankCount = 0;
		int numCount = 0;
		int otherCount = 0;
		for (int i = 0; i < array.length; i++) {
			if ((array[i] >= 'A' && array[i] <= 'Z') || (array[i] >= 'a' && array[i] <= 'z')) {
				charCount++;
			} else if (array[i] == ' ') {
				blankCount++;
			} else if (array[i] >= '0' && array[i] <= '9') {
				numCount++;
			} else {
				otherCount++;
			}
		}
		System.out.println("英文字母出现的次数：" + charCount);
		System.out.println("空格出现的次数：" + blankCount);
		System.out.println("数字出现的次数：" + numCount);
		System.out.println("其他出现的次数：" + otherCount);
	}
	
//	2、int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
//	要求求出其中的奇数个数和偶数个数。
	@Test
	public void test551() {
		int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int oddCount = 0;
		int evenCount = 0;
		for (int i = 0; i < scores.length; i++) {
			if (scores[i] % 2 == 0) {
				evenCount++;
			} else {
				oddCount++;
			}
		}
		System.out.println("奇数个数：" + oddCount);
		System.out.println("偶数个数：" + evenCount);
	}

	
//	3、输入一组学生的成绩，使用数组，然后计算他们的平均值.
//	int[] scores = new int[3];
	@Test
	public void test66() {
		Scanner scanner = new Scanner(System.in);
		int[] scores = new int[3];
		for (int i = 0; i < scores.length; i++) {
			System.out.println("请输入学生成绩：");
			scores[i] = scanner.nextInt();
		}
		int sum = 0;
		for (int i = 0; i < scores.length; i++) {
			sum = sum +scores[i];
		}
		int avg = sum / scores.length;
		System.out.println(avg);
	}
	
	@Test
	public void test5555() {
		short s = 1;
		s = 34;
		// s = 3438483434;// Type mismatch: cannot convert from int to short
		// s = s + 1;// Type mismatch: cannot convert from int to short
		s += 1;// 由于 += 是 java语言规定的运算符，java编译器会对它进行特殊处理，因此可以正确编译。
		System.out.println(s);// 35
	}
}
